<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;

class DeleteDirectory extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'delete:directory';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '删除前一天上传资料创建的临时文件夹';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle(): void
    {
        $storage = Storage::disk('public');
        $yesterday = now()->subDay();
        $directory = 'files/' . $yesterday->year . '/' . $yesterday->month . '/' . $yesterday->day . '/';
        foreach ($storage->directories($directory) as $directory) {
            $storage->deleteDirectory($directory);
        }
    }
}
